package com.c5p1ng.route.util;

import org.springframework.context.ApplicationContext;

/**
 * 全局Spring上下文
 *
 * @author csp
 **/
public class SpringContextUtil {

    private static ApplicationContext applicationContext;

    public static ApplicationContext getContext () {
        return applicationContext;
    }

    public static void setContext(ApplicationContext applicationContext) {
        SpringContextUtil.applicationContext = applicationContext;
    }

    public static <T> T getObject(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }

    public static Object getBean(String clazz) {
        return applicationContext.getBean(clazz);
    }

    public <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }

    private SpringContextUtil(){}

}
